<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="stylesheets/libs/joyride-1.0.5.css">
    <link rel="stylesheet" type="text/css" href="stylesheets/libs/jquery.fancybox-1.3.4.css"/>
    <link rel="stylesheet" type="text/css" href="stylesheets/libs/jquery-ui-1.9.2.custom.css">
    <link rel="stylesheet" type="text/css" href="stylesheets/all/vishViewer.css">
	<script type="text/javascript" src="javascripts/vishViewer.min.js"></script>
</head>

<body onload="start()" style="display: none" class="loaded" id="presentation_iframe">

	<%= render :partial => 'excursions/vish_viewer_scorm.full' %>

	<% unless excursion
		#Get excursion from database if exists and is published
		presId = Integer(json["vishMetadata"]["id"]) rescue nil
		draft = (json["vishMetadata"]["draft"]==="true") rescue true
		unless presId.blank? or draft
			excursion = Excursion.find_by_id(presId)
			excursion = nil if excursion.nil? or excursion.draft
		end
	end %>

	<script>
		options = {};

		var configuration = {};

		configuration["ImagesPath"] = "images/";
		configuration["StylesheetsPath"] = "stylesheets/";

		// Recommendations API
		configuration["recommendationsAPI"] = {
			rootURL: "<%=Vish::Application.config.full_domain%>" + "/excursions/last_slide.json"
		};
		
		//Tracking System
		<%if Vish::Application.config.trackingSystem %>
			configuration["TrackingSystemAPIKEY"] = "<%= Vish::Application.config.APP_CONFIG['trackingSystemAPIKEY'] %>";
			configuration["TrackingSystemAPIURL"] = "<%= Vish::Application.config.APP_CONFIG['trackingSystemAPIURL'] %>";
		<%end%>

		//LOEP configuration
		<% unless Vish::Application.config.APP_CONFIG['loep'].nil? or excursion.nil? %>
			<% loepConfig = Vish::Application.config.APP_CONFIG['loep'] %>
			<% tokenURL = (Vish::Application.config.full_domain + '/loep/session_token.json') %>
			configuration["loepSettings"] = {
				tokenURL: '<%=tokenURL%>',
				domain: '<%=loepConfig["domain"]%>',
				app: '<%=loepConfig["app_name"]%>',
				loId: '<%=excursion.activity_object.getGlobalId()%>',
				evmethod: "wblts"
			};
			<% unless loepConfig["repository_name"].blank? %>
				configuration["loepSettings"]["repository"] = '<%=loepConfig["repository_name"]%>';
			<% end %>
		<% end %>

		options["configuration"] = configuration;
		options["developping"] = false;
		
		options["scorm"] = true;

		<% if excursion %>
			options["watermarkURL"] = "<%=excursion_url(excursion)%>";
		<% else %>
			options["watermarkURL"] = "<%=Vish::Application.config.full_domain%>";
		<% end %>

		var presentation = <%= raw json.to_json %>;

		function start(){
			VISH.Viewer.init(options,presentation);
		}
	</script>

</body>
</html>
